package com.canbot.u05.activity.agenda

import android.app.Activity
import android.content.Intent
import android.text.TextUtils
import android.view.View
import com.canbot.u05.R
import com.canbot.u05.activity.presidemode.newcode.BaseHostActivity
import com.canbot.u05.utils.PathConst
import kotlinx.android.synthetic.main.activity_agenda_permission.*

/**
 * @author yinxiaowei
 * @date 2019/5/31
 */
class AgendaPermissionSetActivity : BaseHostActivity(), View.OnClickListener {
    private val voices = arrayOf(arrayOf("${PathConst.AGENDA_VOICE_DIR}tcqx_gzrc_u05_001.mp3", "43"),
            arrayOf("${PathConst.AGENDA_VOICE_DIR}tcqx_gzrc_u05_002.mp3", "34"))
    private var pwd = false
    override fun initEventData() {
        yes_permission.setOnClickListener(this)
        no_permission.setOnClickListener(this)
        initIntent()
        playRandomVoiceWithEmotion(voices)
    }

    private fun initIntent() {
        pwd = intent.getBooleanExtra(DATA, false)
        if (pwd) {
            yes_permission.isSelected = true
        } else {
            no_permission.isSelected = true
        }
    }

    override fun getLayoutResId(): Int {
        return R.layout.activity_agenda_permission
    }

    fun back(view: View?) {
        exit()
    }

    override fun onBackPressed() {
        exit()
    }

    private fun exit() {
        val intent = Intent()
        intent.putExtra(DATA, pwd)
        setResult(Activity.RESULT_OK, intent)
        finish()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        when (requestCode) {
            REQUEST_PWD -> {
                val pwdTemp = data?.getStringExtra(DATA)
                if (TextUtils.isEmpty(pwdTemp)) {

                } else {
                    pwd = true
                    no_permission.isSelected = false
                    yes_permission.isSelected = true
                }
            }
        }
    }

    override fun onClick(v: View) {
        when (v) {
            yes_permission -> {
//                val intent = Intent()
//                intent.setClass(this, PassWordActivity::class.java)
//                gotoActivityForResult(intent, REQUEST_PWD)
                pwd = true
                no_permission.isSelected = false
                v.isSelected = true
            }
            no_permission -> {
                pwd = false
                yes_permission.isSelected = false
                v.isSelected = true
            }
        }
        exit()
    }
}
